package route

import (
	"time"

	"gitee.com/jiebaiyou/formflow/api/controller"
	"gitee.com/jiebaiyou/formflow/bootstrap"
	"gitee.com/jiebaiyou/formflow/pkg/storage/redis"
	"gitee.com/jiebaiyou/formflow/pkg/storage/sqlite"
	"gitee.com/jiebaiyou/formflow/repository"
	"gitee.com/jiebaiyou/formflow/service"
	"github.com/gin-gonic/gin"
)

// NewRefreshTokenRouter 创建并配置刷新令牌相关的API路由
func NewRefreshTokenRouter(env *bootstrap.Config, timeout time.Duration, db sqlite.DB, cache redis.Database, group *gin.RouterGroup) {
	// 初始化用户仓储
	ur := repository.NewUserRepository(db, cache)
	// 初始化刷新令牌服务
	sr := service.NewRefreshTokenService(ur, timeout)
	// 初始化刷新令牌控制器
	rtc := &controller.RefreshTokenController{
		RefreshTokenService: sr,
		Env:                 env,
	}

	// 刷新令牌路由
	group.POST("/refresh", rtc.RefreshToken)
}
